package a;

import java.nio.file.Path;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine();
        while (n-- > 0) {
            int p = 0;
            String str = sc.nextLine();
            int len=str.length();
            String result="";
//            System.out.println(str);
            for (int i = 0; i < len; i++) {
                char c = str.charAt(i);
                if (c >= '0' && c <= '9') {
//                    System.out.println(11);
                    if (p == 0) {
                        p = (int)(c - '0');
                    } else {
                        p = p * 10 +(int) (c - '0');
                    }
                } else {
                    //字符串向左移动p为
                    //如果p大于\
//                    String str2="";
                    int len2=result.length();
                    if (p<=result.length()&&len2>0){
                        result  = result.substring(p%len2) + result.substring(0, p%len2);
                    }else if (p>result.length()&&len2>0){
                        result = result.substring(p%result.length()) + result.substring(0, p%result.length());
                    }
                    StringBuffer sb = new StringBuffer(result);
                    if (c == 'R') {
                        result = sb.reverse().toString();
                    } else {
                        result = sb.append(c).toString();
                    }
                    p=0;
                }
//                System.out.println(result);
            }
            System.out.println(result);
        }
    }
}
